﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QLKS.Templates;

namespace QLKS.Views
{
    /// <summary>
    /// Interaction logic for frmRestore.xaml
    /// </summary>
    public partial class frmRestore : FormTrans
    {
        System.Windows.Forms.FolderBrowserDialog PathBrowser1 = new System.Windows.Forms.FolderBrowserDialog();
        System.Windows.Forms.FolderBrowserDialog PathBrowser2 = new System.Windows.Forms.FolderBrowserDialog();
        

        public frmRestore()
        {
            InitializeComponent();
            txtInputPath.Text = System.Windows.Forms.Application.StartupPath + "\\Data";
            txtOutputPath.Text = System.Windows.Forms.Application.StartupPath + "\\Data";
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtInputPath.Text))
            {
                MessageBox.Show(M_LAN.Equals("V")?"Chưa nhập đường dẫn file .Bak!":"please input path of file .Bak", "QLKS", MessageBoxButton.OK, MessageBoxImage.Error);
                btnBrowse1.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txtOutputPath.Text))
            {
                MessageBox.Show(M_LAN.Equals("V")?"Chưa nhập đường dẫn dữ liệu!":"please input path of data", "QLKS", MessageBoxButton.OK, MessageBoxImage.Error);
                btnBrowse2.Focus();
                return;
            }

            frmProgressBar frm = new frmProgressBar();
            frm.SetValue(70);
            frm.Show();
            if (Models.DataProviderModel.Restore(txtInputPath.Text,txtOutputPath.Text))
            {
                MessageBox.Show(M_LAN.Equals("V")?"Thực hiện thành công!":"Perform successful", "QLKS", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            frm.SetValue(100);
            frm.Close();
        }

        private void btnBrowse1_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog BrowsePath = new System.Windows.Forms.OpenFileDialog();
            BrowsePath.InitialDirectory = txtInputPath.Text;
            BrowsePath.Filter = "Files Bak|*.bak|All File|*.*";
            if (BrowsePath.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                return;
            txtInputPath.Text = BrowsePath.FileName;
        }

        private void btnBrowse2_Click(object sender, RoutedEventArgs e)
        {
            PathBrowser2.SelectedPath = txtOutputPath.Text;
            if (PathBrowser2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtOutputPath.Text = PathBrowser2.SelectedPath;
                // Models.CloneOptionsModel.SourcePath = SourcePathBrowser.SelectedPath;
            }
        }
    }
}
